package com.hrzyit.whistle.ui.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.hrzyit.base.ui.adapter.BaseRecyclerViewAdapter
import com.hrzyit.base.widgets.MainPageButton
import com.hrzyit.whistle.R
import kotlinx.android.synthetic.main.layout_image_text_button.view.*

/**
 * App 首页功能按钮适配器
 * @author YangWei
 * @date 2019/4/19
 */
class MainPageFuncButtonAdapter(context: Context):
    BaseRecyclerViewAdapter<MainPageButton, MainPageFuncButtonAdapter.ViewHolder>(context) {

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
            val view = LayoutInflater.from(mContext)
                .inflate(R.layout.layout_image_text_button, parent, false)

            return ViewHolder(view)
        }

        /**
         * 绑定视图
         */
        override fun onBindViewHolder(holder: ViewHolder, position: Int) {

            super.onBindViewHolder(holder, position)

            val mainPageButton = dataList[position]

            val mainPageBtnCt = holder.itemView.findViewWithTag<LinearLayout>("tag_main_func_btn")

            // 设置每个功能按钮容器id
            mainPageBtnCt.id = mainPageButton.id

            holder.itemView.mTopIv.setImageDrawable(mainPageButton.drawableIcon)
//            val bottomTv = mainPageBtnCt.findViewById<TextView>(R.id.mBottomTv)
            holder.itemView.mBottomTv.text = mainPageButton.text

        }

        /**
         * 返回数据记录数
         */
        override fun getItemCount(): Int {
            return dataList.size
        }

        class ViewHolder(view: View) : RecyclerView.ViewHolder(view)
}